package com.gogant.spider.demo.oschina;

import com.gogant.spider.core.SpiderException;
import com.gogant.spider.http.HttpResponse;
import com.gogant.spider.http.HttpSpider;
import com.gogant.spider.http.HttpURLHandler;
import com.gogant.spider.js.PhantomPool;
import java.net.URL;

public class OSChinaDemo {
	public static void main(String[] args) throws SpiderException{
		PhantomPool.initPool(5, "phantomjs/windows/phantomjs.exe", "phantomjs/proxy.js");
		HttpSpider spider = new HttpSpider(10);
		spider.addURLHandler(new HttpURLHandler() {

			public void onResponse(HttpResponse resp) {
				Article a = null;
				try {
					a = resp.getBean(Article.class);
				} catch (Exception e) {
					e.printStackTrace();
				}
				if (a == null) {
					return;
				}
				System.out.println("标题：" + a.getTitle());
				System.out.println("作者：" + a.getAuthor());
				System.out.println("时间：" + a.getPubDate());
				System.out.println("内容：" + a.getContent());
			}

			public void onException(URL url, Throwable e) {
				e.printStackTrace();
			}
		});
		spider.fetch("http://www.oschina.net/news/57326");
	}
}
